﻿'
' AnyRip (C) 2011 Rick Winkler
'
' This file is part of AnyRip.
' 
' AnyRip is free software: you can redistribute it and/or modify
' it under the terms of the GNU General Public License as published by
' the Free Software Foundation, either version 3 of the License, or
' (at your option) any later version.
'
' AnyRip is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
' GNU General Public License for more details.
'
' You should have received a copy of the GNU General Public License
' along with AnyRip.  If not, see <http://www.gnu.org/licenses/>.
'
Imports System.Diagnostics
Imports System.IO
Imports System.Threading
Imports System.String

Module Utils

    Private _XmlDocument As New System.Xml.XmlDocument

    ''' <summary>
    ''' Writes the header.
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub WriteHeader()
        Console.WriteLine(My.Resources.Header)
    End Sub

    ''' <summary>Outputs a formatted line to the screen.</summary>
    ''' <param name="_Line">The string to print to a line.</param>
    ''' <remarks></remarks>
    Public Sub WriteLine(ByVal _Line As String)
        Console.WriteLine("[" & Date.Now().ToString("HH:mm:ss") & "] " & _Line)
    End Sub

    Public Function GetArgument(ByVal _Argument As String) As String
        Return Nothing
    End Function

    ''' <summary>
    ''' Loads the settings file.
    ''' </summary>
    ''' <param name="_File">The _ file.</param>
    ''' <remarks></remarks>
    Public Sub LoadSettingsFile(ByVal _File As String)
        If File.Exists(_File) Then
            Utils.WriteLine("Loading settings file " & _File)
            _XmlDocument.Load(_File)
        Else
            Utils.WriteLine("Could not find settings file " & _File)
            Environment.Exit(1)
        End If
    End Sub

    ''' <summary>Gets the value of a setting from xml file.</summary>
    ''' <param name="_Setting">The name of the setting to retrieve.</param>
    ''' <returns>Value as String</returns>
    ''' <remarks></remarks>
    Public Function GetSetting(ByVal _Setting As String) As String

        ' Loop through settings. Return requested setting.
        For Each _XmlElement As System.Xml.XmlElement In _XmlDocument.GetElementsByTagName("setting")
            If _XmlElement.GetAttribute("name").ToString = _Setting Then
                Return _XmlElement.InnerText
            End If
        Next

        ' Return Nothing if setting not found
        Return Nothing

    End Function

End Module
